home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Juegos / King of Skeleton / King of Skeleton.swf / scripts / __Packages / Player.as < prev    next >
Encoding:
Text File  |  2006-02-02  |  3.8 KB  |  142 lines

  1. class Player extends MovieClip
  2. {
  3.    var v;
  4.    var snd;
  5.    var ts;
  6.    var track;
  7.    var z;
  8.    var head;
  9.    var a = 0;
  10.    var d = 0;
  11.    var ps = 0;
  12.    var va = 0;
  13.    var rv = 0;
  14.    var sndOff = false;
  15.    static var iv = 10;
  16.    static var g = 1;
  17.    static var f = 0.995;
  18.    static var lc = 0.000033333333333333335;
  19.    static var cfc = 8900;
  20.    static var rs = 0.5;
  21.    static var rd = 0.93;
  22.    static var gc = 0.56;
  23.    function Player()
  24.    {
  25.       super();
  26.       this.v = new Vector(0,0);
  27.       this.ps = Player.iv;
  28.       this.snd = new Sound(this);
  29.       this.snd.attachSound("movement");
  30.       if(!_root.brdcst)
  31.       {
  32.          _root.brdcst = {};
  33.          AsBroadcaster.initialize(_root.brdcst);
  34.       }
  35.       _root.brdcst.addListener(this);
  36.       if(this._parent.sndOff)
  37.       {
  38.          this.sndOff = true;
  39.       }
  40.       if(!this.sndOff)
  41.       {
  42.          this.snd.start(0,999999999);
  43.          this.snd.setVolume(0);
  44.       }
  45.    }
  46.    function sndChange(t)
  47.    {
  48.       if(t)
  49.       {
  50.          this.snd.stop();
  51.       }
  52.       else
  53.       {
  54.          this.snd.start(0,999999999);
  55.       }
  56.    }
  57.    function move(ftime, ia)
  58.    {
  59.       var _loc8_ = this.track.getHeightAt(this.ts,this.d + 1);
  60.       var _loc6_ = Math.atan2(_loc8_ - this.z,1);
  61.       this.va = - Math.sin(_loc6_);
  62.       this.ps += this.va * Player.g;
  63.       if(!this.ts.s)
  64.       {
  65.          var _loc9_ = Math.sqrt(Math.abs(this._rotation - ia));
  66.       }
  67.       else
  68.       {
  69.          _loc9_ = 0;
  70.       }
  71.       this.ps *= 1 - Player.lc * _loc9_ * ftime;
  72.       this.ps *= Player.f;
  73.       this.ps = this.ps <= Vars.tVel ? this.ps : Vars.tVel;
  74.       this.snd.setVolume(this.ps / Vars.tVel * 100);
  75.       var _loc4_ = this.ps / 1000;
  76.       var _loc7_ = this.ps / 1000 * ftime;
  77.       this.d += _loc7_;
  78.       var _loc3_ = this.track.length;
  79.       var _loc2_ = 0;
  80.       while(_loc2_ < _loc3_)
  81.       {
  82.          if(this.track[_loc2_].tl + this.track[_loc2_].l > this.d)
  83.          {
  84.             break;
  85.          }
  86.          if(this.track[_loc2_] == undefined)
  87.          {
  88.             this.raceEnded();
  89.             return 0;
  90.          }
  91.          this.track.shift();
  92.          _loc2_ = _loc2_ - 1;
  93.          _loc2_ = _loc2_ + 1;
  94.       }
  95.       this.ts = this.track[_loc2_];
  96.       if(Key.isDown(39))
  97.       {
  98.          this.rv -= Player.rs;
  99.       }
  100.       if(Key.isDown(37))
  101.       {
  102.          this.rv += Player.rs;
  103.       }
  104.       this.rv -= Player.gc * Math.sin(this._rotation * Trig.dr);
  105.       ┬º┬ºpush(Key.isDown(39) && !Key.isDown(37) ? this.gotoAndStop("tiltRight") : (Key.isDown(37) && !Key.isDown(39) ? this.gotoAndStop("tiltLeft") : this.gotoAndStop("flat")));
  106.       if(!this.ts.s)
  107.       {
  108.          this.rv += _loc4_ * _loc4_ * Player.cfc / this.ts.r * this.ts.d;
  109.       }
  110.       this.rv *= Player.rd;
  111.       this._rotation += this.rv * 0.03 * ftime;
  112.       this.head._rotation = - this._rotation / 2;
  113.       var _loc5_ = this.d - this.ts.tl;
  114.       if(this.ts.s)
  115.       {
  116.          this.v.x = this.ts.x + _loc5_ * Math.cos(this.ts.a);
  117.          this.v.y = this.ts.y + _loc5_ * Math.sin(this.ts.a);
  118.          this.a = this.ts.a;
  119.       }
  120.       else
  121.       {
  122.          this.a = _loc5_ / this.ts.r * this.ts.d + this.ts.a - Trig.ra * this.ts.d;
  123.          this.v.x = this.ts.cx + this.ts.r * Math.cos(this.a);
  124.          this.v.y = this.ts.cy + this.ts.r * Math.sin(this.a);
  125.          this.a += Trig.ra * this.ts.d;
  126.       }
  127.       this.z = this.track.getHeightAt(this.ts,this.d);
  128.       return _loc4_;
  129.    }
  130.    function raceEnded()
  131.    {
  132.       this._parent.brdcst.broadcastMessage("endRace");
  133.       this._parent.times.t = this._parent.time;
  134.       this.snd.stop();
  135.       delete this.snd;
  136.       this._parent.messages.gotoAndStop(1);
  137.       this._parent.warning_signs.gotoAndStop(1);
  138.       this._parent.messages._visible = false;
  139.       this._parent.gotoAndStop("endRace");
  140.    }
  141. }
  142.